<?php
/**
 * Created by PhpStorm.
 * User: zhj
 * Date: 2019/4/8
 * Time: 15:00
 */

namespace app\admin\logic;

/**
 * 行为日志逻辑
 */
class Fields extends AdminBase
{

    /**
     * 获取数据列表名
     * @param int $type 0 编辑页，1列表页
     * @return array
     */
    public function getFieldsList($type=0)
    {
        $fields = $this->modelFields->getListSelf([], 'sort asc',100)->toArray();
        if($type){
            $list = [] ;
            $list = $fields;
        }else{
            $list = [] ;
            foreach ($fields as $k=>$v){
                $list[$v['field']]=$v['name'];
            }
        }
        return $list;
    }

    /**
     * 日志删除
     */
    public function logDel($where = [])
    {

        return $this->modelActionLog->deleteInfo($where) ? [RESULT_SUCCESS, '日志删除成功'] : [RESULT_ERROR, $this->modelActionLog->getError()];
    }

    /**
     * 日志添加
     */
    public function logAdd($name = '', $describe = '')
    {

        $member_info = session('member_info');

        $request = request();

        $data['member_id'] = $member_info['id'];
        $data['username']  = $member_info['username'];
        $data['ip']        = $request->ip();
        $data['url']       = $request->url();
        $data['status']    = DATA_NORMAL;
        $data['name']      = $name;
        $data['describe']  = $describe;

        $url = url('logList');

        return $this->modelActionLog->setInfo($data) ? [RESULT_SUCCESS, '日志添加成功', $url] : [RESULT_ERROR, $this->modelActionLog->getError()];
    }
}
